package sumpayTest7;

import java.util.LinkedList;
import java.util.Queue;



public class Node<Key,Value> {
		Key key;
		Value value;
		Node left,right;
		boolean color;
		int n;
		Node(Key key, Value value, int n, boolean color) {
			super();
			this.key = key;
			this.value = value;
			this.n=n;
			this.color = color;
		}
		 void PreOrderPrint(){  
			 	
			    System.out.print(key.toString()+"-"+color + " ");  
			    if(left != null)  
			    	 left.PreOrderPrint();  
			    if(right != null)  
			    	right.PreOrderPrint();  
			}
		 void LevelOrderPrint(){  
		        if(this == null)  
		            throw new IllegalArgumentException("null node !");  
		        Queue<Node> queue1 = new LinkedList<Node>();  
		        Queue<Node> queue2 = new LinkedList<Node>();  
		        queue1.add(this);  
		        while(!queue1.isEmpty() || !queue2.isEmpty()){  
		            if(queue2.isEmpty()){  
		                while(!queue1.isEmpty()){  
		                    Node currentNode = queue1.poll();  
		                    System.out.print(currentNode.key.toString()+"-"+currentNode.color + " ");  
		                    if(currentNode.left != null){  
		                        queue2.add(currentNode.left);  
		                    }  
		                    if(currentNode.right != null){  
		                        queue2.add(currentNode.right);  
		                    }  
		                }  
		            }  
		            else{  
		                while(!queue2.isEmpty()){  
		                    Node currentNode = queue2.poll();  
		                    System.out.print(currentNode.key.toString()+"-"+currentNode.color  + " ");  
		                    if(currentNode.left != null){  
		                        queue1.add(currentNode.left);  
		                    }  
		                    if(currentNode.right != null){  
		                        queue1.add(currentNode.right);  
		                    }  
		                }  
		            }  
		            System.out.println();  
		        }  
		    }  
}
